﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Diploma.Models;
using Diploma.Models.Entities;

namespace DiplomaWeb.Models.CompaniesAndLecturers
{
    public class LecturerLevelInfoViewModel
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public int MaxValue { get; set; }
        public List<CompanyViewModel> Companies { get; set; }
        public IEnumerable<SelectListItem> SelectListCompanies
        {
            get { return DataManager.Instance.CompaniesRepository.GetAllForLevel(Id).Select(r => new SelectListItem
                                                                                                     {
                                                                                                         Value = r.Id.ToString(),
                                                                                                         Text = r.DisplayName
                                                                                                     }); }
        }

        public void ToViewModel(LecturersForPractice item, IEnumerable<LecturerInCompanyEntity> companies)
        {
            Id = item.QualificationLevelId;
            Name = item.QualificationLevel.Name;
            MaxValue = item.MaxSudents;
            Companies = companies.Where(r => r.LevelId == Id).Select(r => new CompanyViewModel(r)).ToList();
        }
    }
}